/*
 * 文 件    名:  NewsCornerModel.java
 * 创建日期:  2012-10-25下午2:40:28
 * 版          权:  Epro Technologies Co., Ltd. Copyright 2011-2012,  All rights reserved
 * 作          者:  tj072
 */
package com.weipu.common.facade.model;

import java.io.Serializable;

import org.json.JSONObject;

import com.weipu.common.constants.ServerConstant;
import com.weipu.common.util.Logger;

/** 
 * @Description  新闻角model
 * @version [版本号, 2012-10-29]
 * @see [相关类/方法]
 * @since [产品/模块版本]
 * 
 * @author tj072
 */
public class NewsCornerModel implements Serializable
{
    
    /** 
     * @Fields serialVersionUID : 序列版本号
     */
    private static final long serialVersionUID = 7972608964433196434L;
    
    /**
     * id
     */
    private String newId;
    
    /**
     * 新闻角落标题
     */
    private String newTitle;
    
    /**
     * 新闻角落详情
     */
    private String newContent;
    
    /**
     * 大图
     */
    private String bigImg;
    
    /**
     * 小图
     */
    private String smallImg;
    
    /**
     * 创建时间
     */
    private String createDate;
    
    /**
     * 修改时间
     */
    private String editDate;
    
    /**
     * (本地数据更新时间，用于本地数据缓存，单位：毫秒
     */
    public long cacheUpdateTime;
    
    public long getCacheUpdateTime()
    {
        return cacheUpdateTime;
    }
    
    public void setCacheUpdateTime(long cacheUpdateTime)
    {
        this.cacheUpdateTime = cacheUpdateTime;
    }
    
    public String getNewId()
    {
        return newId;
    }
    
    public void setNewId(String newId)
    {
        this.newId = newId;
    }
    
    public String getNewTitle()
    {
        return newTitle;
    }
    
    public void setNewTitle(String newTitle)
    {
        this.newTitle = newTitle;
    }
    
    public String getNewContent()
    {
        return newContent;
    }
    
    public void setNewContent(String newContent)
    {
        this.newContent = newContent;
    }
    
    public String getBigImg()
    {
        return bigImg;
    }
    
    public void setBigImg(String bigImg)
    {
        this.bigImg = bigImg;
    }
    
    public String getSmallImg()
    {
        return smallImg;
    }
    
    public void setSmallImg(String smallImg)
    {
        this.smallImg = smallImg;
    }
    
    public String getCreateDate()
    {
        return createDate;
    }
    
    public void setCreateDate(String createDate)
    {
        this.createDate = createDate;
    }
    
    public String getEditDate()
    {
        return editDate;
    }
    
    public void setEditDate(String editDate)
    {
        this.editDate = editDate;
    }
    
    public static long getSerialversionuid()
    {
        return serialVersionUID;
    }
    
    //    public JSONObject tojson()
    //    {
    //        JSONObject json = new JSONObject();
    //        
    //        try
    //        {
    //            if (0 != id)
    //            {
    //                json.put("id", id);
    //            }
    //            
    //            if (null != smallPictureUrl)
    //            {
    //                json.put("smallPictureUrl", smallPictureUrl);
    //            }
    //            if (null != title)
    //            {
    //                json.put("title", title);
    //            }
    //            
    //            if (null != bigPictureUrl)
    //            {
    //                json.put("bigPictureUrl", bigPictureUrl);
    //            }
    //            if (null != newsDescription)
    //            {
    //                json.put("newsDescription", newsDescription);
    //            }
    //        }
    //        catch (JSONException e)
    //        {
    //        }
    //        
    //        return json;
    //    }
    
    /**
     * JSON对象转存到新闻model
     * @param json
     * @return  NewsCornerModel对象
     * @return NewsCornerModel
     * @exception throws [违例类型] [违例说明]
     * @see [类、类#方法、类#成员]
    */
    public static NewsCornerModel json2NewsCornerModel(JSONObject json)
    {
        NewsCornerModel model = new NewsCornerModel();
        if (null != json)
        {
            if (json.optString(ServerConstant.NewsCorner.CONSTANT_NEWID) != JSONObject.NULL
                && !json.isNull(ServerConstant.NewsCorner.CONSTANT_NEWID))
            {
                model.setNewId(json.optString(ServerConstant.NewsCorner.CONSTANT_NEWID));
            }
            if (json.optString(ServerConstant.NewsCorner.CONSTANT_NEWTITLE) != JSONObject.NULL
                && !json.isNull(ServerConstant.NewsCorner.CONSTANT_NEWTITLE))
            {
                model.setNewTitle(json.optString(ServerConstant.NewsCorner.CONSTANT_NEWTITLE));
            }
            if (json.optString(ServerConstant.NewsCorner.CONSTANT_NEWCONTENT) != JSONObject.NULL
                && !json.isNull(ServerConstant.NewsCorner.CONSTANT_NEWCONTENT))
            {
                model.setNewContent(json.optString(ServerConstant.NewsCorner.CONSTANT_NEWCONTENT));
            }
            if (json.optString(ServerConstant.NewsCorner.CONSTANT_BIGIMG) != JSONObject.NULL
                && !json.isNull(ServerConstant.NewsCorner.CONSTANT_BIGIMG))
            {
                model.setBigImg(json.optString(ServerConstant.NewsCorner.CONSTANT_BIGIMG));
            }
            if (json.optString(ServerConstant.NewsCorner.CONSTANT_SMALLIMG) != JSONObject.NULL
                && !json.isNull(ServerConstant.NewsCorner.CONSTANT_SMALLIMG))
            {
                model.setSmallImg(json.optString(ServerConstant.NewsCorner.CONSTANT_SMALLIMG));
            }
            
            model.setCacheUpdateTime(System.currentTimeMillis());//设置缓存时间
        }
        Logger.d("model", model.getNewTitle());
        return model;
    }
    
    /**
      * JSON字符串转存到新闻model
      * @param jsonString
      * @return  NewsCornerModel对象
      * @return NewsCornerModel [返回类型说明]
      * @exception throws [违例类型] [违例说明]
      * @see [类、类#方法、类#成员]
     */
    //    public static NewsCornerModel json2NewsCornerModel(String jsonString)
    //    {
    //        if (null == jsonString || "".equals(jsonString.trim()))
    //        {
    //            return null;
    //        }
    //        
    //        NewsCornerModel model = null;
    //        try
    //        {
    //            JSONObject json = new JSONObject(jsonString);
    //            model = json2NewsCornerModel(json);
    //        }
    //        catch (JSONException e)
    //        {
    //        }
    //        return model;
    //    }
    
    /**  
      *  JSON数组转存到数组列表
      * @param arrays
      * @return  NewsCornerModel对象的数组
      * @return ArrayList<NewsCornerModel> 
      * @exception throws [违例类型] [违例说明]
      * @see [类、类#方法、类#成员]
     */
    //    public static ArrayList<NewsCornerModel> jsonArray2NewsCornerModel(
    //            JSONArray arrays)
    //    {
    //        ArrayList<NewsCornerModel> NewsCornerModelList = null;
    //        if (null != arrays && arrays.length() > 0)
    //        {
    //            NewsCornerModelList = new ArrayList<NewsCornerModel>(
    //                    arrays.length());
    //            for (int i = 0; i < arrays.length(); i++)
    //            {
    //                NewsCornerModelList.add(NewsCornerModel.json2NewsCornerModel(arrays.optJSONObject(i)));
    //            }
    //        }
    //        return NewsCornerModelList;
    //    }
}
